package cn.tradewin.advisor.pages.security;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.advisor.persist.model.Roles;
import cn.tradewin.advisor.persist.services.AdvisorSecurityService;

public class AddRole {
	
	@Property
	private Roles role;
	
	@Inject
	private Logger log;
	
	@Inject
	private AdvisorSecurityService securityService;
	
	@Log
	void onPrepare() throws Exception {
		if (role == null) {
			role = new Roles();
			role.setRoleId(securityService.getMaxRoleId());
		}
	}

	@Log
	Object onSubmit() {
		try {
			securityService.addRole(role);
		} catch (Exception e) {
			log.debug(e.getMessage());
		}
		return RoleBoard.class;
	}
}
